package com.angel.application.commandgateways;

import com.angel.application.assembler.AngelUserAssembler;
import com.angel.application.dto.AngelUserInfoDTO;
import com.angel.domain.angeluser.aggregates.AngelUser;
import com.angel.domain.angeluser.repositories.AngelUserRepository;
import com.angel.domain.angeluser.valueobjects.AngelUserId;
import org.springframework.stereotype.Service;

import java.util.Optional;

/*
 * 更新关注微信公众号： 为了offer
 * @author parkin
 * @description
 * @date 2021/11/13
 */
@Service
public class AngelUserCommandService {

    private final AngelUserRepository angelUserRepository;

    public AngelUserCommandService(AngelUserRepository angelUserRepository) {
        this.angelUserRepository = angelUserRepository;
    }

    // 获取AngelUser
    public AngelUserInfoDTO get(AngelUserId angelUserId) {
        Optional<AngelUser> angelUser = angelUserRepository.get(angelUserId);
        return AngelUserAssembler.toAngelUserInfoDTO(
                angelUser.orElseThrow(() -> new RuntimeException("the user is not existed"))
        );
    }

}
